<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category   design_default
 * @package    Mage
 * @copyright  Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
 * @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php
/**
 * Product list template
 *
 * @see Sf_Bestsellingproduct_Block_Bestsellingproductpage
 */
?>
<h3><?php echo $this->__('Bestselling Products') ?></h3>
<?php $value=$this->getRequest()->getParam('value');?>
<?php $mode=$this->getRequest()->getParam('mode');?>
<?php $catId=$this->getRequest()->getParam('cat_id');?>
<?php $categories=$this->getAllCategory(); ?>
<?php $_productCollection=$this->getLoadedProductCollection() ?>
<?php $_columnCount=3?>
<?php if(!$_productCollection->count()): ?>
<div class="note-msg">
    <?php echo $this->__('There are no products matching the selection.') ?>
</div>
<?php else: ?>
<div style="float:left; margin-right:10px">
<label>Category</label>
<select onchange="setLocation(this.value)" >
<option value="<?php echo $this->getUrl('bestselling'); if(!empty($value)):echo '?value='.$value;endif; if(!empty($mode)):echo '&mode='.$mode;endif; ?>">All</option>
<?php foreach($categories as $category):?>
	<?php $name=$category->getName();?>
	<?php if(!empty($name)):?>
		<option value="<?php echo $this->getUrl('bestselling');echo '?cat_id='.$category->getEntityId();if(!empty($value)):echo '&value='.$value;endif; if(!empty($mode)):echo '&mode='.$mode;endif; ?>" <?php if($this->getRequest()->getParam('cat_id')==$category->getEntityId()):echo ' selected="selected" '; endif; ?> ><?php echo $category->getName(); ?></option>
	<?php endif;?>
<?php endforeach;?>
</select>
</div>
<div><label>Time:</label>
<select   onchange="setLocation(this.value)" >
<option value="<?php echo $this->getUrl('bestselling').'?value=0'; if($this->getRequest()->getParam('mode')=='list'):echo '&mode=list';endif; if(isset($catId)):echo '&cat_id='.$catId;endif;?>"<?php if($this->getRequest()->getParam('value')==0):echo ' selected="selected" '; endif; ?>>All Time</option>
<option value="<?php echo $this->getUrl('bestselling').'?value=1'; if($this->getRequest()->getParam('mode')=='list'):echo '&mode=list';endif; if(isset($catId)):echo '&cat_id='.$catId;endif;?>" <?php if($this->getRequest()->getParam('value')==1):echo ' selected="selected" '; endif;  ?>>last month</option>
<option value="<?php echo $this->getUrl('bestselling').'?value=2'; if($this->getRequest()->getParam('mode')=='list'):echo '&mode=list';endif; if(isset($catId)):echo '&cat_id='.$catId;endif;?>" <?php if($this->getRequest()->getParam('value')==2):echo ' selected="selected" '; endif; ?>>last six month</option>
<option value="<?php echo $this->getUrl('bestselling').'?value=3'; if($this->getRequest()->getParam('mode')=='list'):echo '&mode=list';endif; if(isset($catId)):echo '&cat_id='.$catId;endif; ?>" <?php if($this->getRequest()->getParam('value')==3):echo ' selected="selected" '; endif; ?>>last year</option>
</select>
</div>
<div class="clear">&nbsp;</div>
<?php echo $this->getToolbarHtml() ?>
<?php // List mode ?>
<?php if($this->getMode()!='grid'): ?>
<?php $_iterator = 0; ?>
<div class="listing-type-list catalog-listing">
 <ol class="products-list" id="products-list-home">
<?php foreach ($_productCollection as $_product): ?>
   
	<?php $_product = Mage::getModel('catalog/product')->load($_product->getEntityId()); ?>
	  <li class="item<?php if( ++$_iterator == sizeof($_productCollection) ): ?> last<?php endif; ?>">
        <?php // Product Image ?>
        
            <a class="product-image"  href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getSmallImageLabel()) ?>">
                <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135, 135); ?>" width="135" height="135" alt="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" title="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" />
            </a>
        

        <?php // Product description ?>
        <div class="product-shop">
		 <div class="f-fix">
            <h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><?php echo $this->htmlEscape($_product->getName())?></a></h2>
            <?php //if($_product->getRatingSummary()): ?>
            <?php echo $this->getReviewsSummaryHtml($_product) ?>
            <?php //endif; ?>
            <?php echo $this->getPriceHtml($_product, true) ?>
            <p>
	            <?php if($_product->getIsSalable()): ?>
	            <button class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><?php echo $this->__('Add to Cart') ?></span></button>
	            <?php else: ?>
	            <div class="out-of-stock"><?php echo $this->__('Out of stock') ?></div>
	            <?php endif; ?>
            </p>
            <div class="clear"></div>
            <div class="desc std">
                <?php echo nl2br($_product->getShortDescription()) ?>
                <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><small><?php echo $this->__('Learn More') ?></small></a>
            </div>
            <ul class="add-to-links">
                <?php if ($this->helper('wishlist')->isAllow()) : ?>
                <li>
                <a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="link-cart"><?php echo $this->__('Add to Wishlist') ?></a>
                </li>
                <?php endif; ?>
                <?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
                <span class="pipe">|</span>
                <li><a href="<?php echo $_compareUrl ?>"><?php echo $this->__('Add to Compare') ?></a></li>
                <?php endif; ?>
            </ul>
		<div>
        </div>
    </li>
<?php endforeach; ?>
</ol>
</div>
  <script type="text/javascript">decorateList('products-list', 'none-recursive')</script>
<?php else: ?>

<?php // Grid Mode ?>
<div class="listing-type-grid catalog-listing">
<?php $_collectionSize = $_productCollection->count() ?>
    <?php $_columnCount = 4 ?>
    <?php $i=0; foreach ($_productCollection as $_product): ?>
		
		<?php $_product = Mage::getModel('catalog/product')->load($_product->getEntityId()); ?>
		
        <?php if($i++%$_columnCount==0): ?>
        <ul class="products-grid">
        <?php endif; ?>
            <li class="item">
                <p class="product-image">
                    <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>">
                        <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135, 135); ?>" width="135" height="135" alt="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" title="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" />
                    </a>
                </p>
                <h5><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><?php echo $this->htmlEscape($_product->getName()) ?></a></h5>
                <?php //if($_product->getRatingSummary()): ?>
                <?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
                <?php //endif; ?>
                <?php echo $this->getPriceHtml($_product, true) ?>
                <?php if($_product->getIsSalable()): ?>
                    <button type="button" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><?php echo $this->__('Add to Cart') ?></span></button>
                <?php else: ?>
                <div class="out-of-stock"><?php echo $this->__('Out of stock') ?></div>
                <?php endif; ?>
                <p class="add-to">
                    <?php if ($this->helper('wishlist')->isAllow()) : ?>
                    <a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="link-cart"><?php echo $this->__('Add to Wishlist') ?></a>
                    <?php endif; ?>
                    <?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?><br/>
                    <a href="<?php echo $_compareUrl ?>"><?php echo $this->__('Add to Compare') ?></a>
                    <?php endif; ?>
                </p>
            </li>
        <?php if($i%$_columnCount==0 || $i==$_collectionSize): ?>
        </ul>
        <?php endif; ?>
    <?php endforeach ?>
     <script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script>
</div>
<?php endif; ?>

<?php echo $this->getToolbarHtml() ?>
<?php endif; ?>
